import React from 'react'
import { Form as FormilyForm } from '@formily/antd'
import { SchemaApp } from '../index'
import { useFieldSchema } from '@formily/react'

export interface FormProps extends React.ComponentProps<typeof FormilyForm> {
  scope?: Record<string, any>
}
export const Form = (props: FormProps) => {
  const fieldSchema = useFieldSchema()
  const componentProps = fieldSchema['x-component-props']
  fieldSchema['x-component'] = 'FormBase'
  const name = fieldSchema['x-designable-id']
  const schema = {
    type: 'void',
    properties: {
      [name]: fieldSchema,
    },
  }

  return (
    <SchemaApp pageSchema={{ formProps: componentProps, schema: schema }} />
  )
}

export const FormBase = (props: any) => {
  return props.children
}
